#include "stdafx.h"
#include "SoftPhoneWrapper.h"


_ATL_FUNC_INFO OnScreenPopDataArrivalInfo = { CC_STDCALL, VT_EMPTY, 1 , {VT_BSTR}};
CSoftPhoneWrapper::CSoftPhoneWrapper()
{
}


CSoftPhoneWrapper::~CSoftPhoneWrapper()
{
}
HWND CSoftPhoneWrapper::Create(
	_In_opt_ HWND hWndParent,
	_In_ _U_RECT rect,
	_In_opt_z_ LPCTSTR szWindowName,
	_In_ DWORD dwStyle,
	_In_ DWORD dwExStyle,
	_In_ _U_MENUorID MenuOrID ,
	_In_opt_ LPVOID lpCreateParam )
{
	HWND hWnd = CWindow::Create(GetWndClassName(), hWndParent, rect, szWindowName, dwStyle, dwExStyle, MenuOrID, lpCreateParam);
	BOOL bCreateCtrl = FALSE;
	try{
		LPOLESTR pszName = OLESTR("XSPHONEACTIVEX.XSPhoneActiveXCtrl.1");
		CComPtr<IUnknown> spControl;
		HRESULT hr = CreateControlEx(pszName, NULL, NULL, &spControl, GUID_NULL, NULL);
		if (SUCCEEDED(hr))
		{
			hr = spControl->QueryInterface(__uuidof(_DXSPhoneActiveX), (void**)&m_SPCControl);
			if (SUCCEEDED(hr))
			{
				hr = DispEventAdvise((IUnknown*)m_SPCControl);
				if (SUCCEEDED(hr))
				{
					m_SPCControl->actionInit();
					
					bCreateCtrl = TRUE;
				}
			}			
		}
	}
	catch (...)
	{

	}
	if (bCreateCtrl){
		return hWnd;
	}
	else{
		return NULL;
	}
		
	//return CWindow::Create(GetWndClassName(), hWndParent, rect, szWindowName, dwStyle, dwExStyle, MenuOrID, lpCreateParam);
}
BOOL CSoftPhoneWrapper::DestoryWindow()
{
	HRESULT hr;
	if (m_SPCControl){
		m_SPCControl->actionUninit();
		hr = DispEventUnadvise((IUnknown*)m_SPCControl);
		m_SPCControl.Release();
		CAxWindow::DestroyWindow();
	}
	return TRUE;
}
STDMETHODIMP CSoftPhoneWrapper::OnScreenPopDataArrival(BSTR strEvtMsg)
{
	return S_OK;
}

